//-----------------------------------------------------------------------
// <copyright file="MethodParameterElementCollection.cs" company="iron9light">
//      Copyright (c) iron9light. All rights reserved.
// </copyright>
// <author>iron9light</author>
//-----------------------------------------------------------------------

namespace EventBrokerExtension.Configuration
{
    using System.Configuration;

    using Microsoft.Practices.Unity.Configuration;

    /// <summary>
    /// A configuration collection of parameters for a method or constructor.
    /// </summary>
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1010:CollectionsShouldImplementGenericInterface", Justification = "Checked.")]
    public class MethodParameterElementCollection : TypeResolvingConfigurationElementCollection
    {
        /// <summary>
        /// Gets the element at the given index.
        /// </summary>
        /// <param name="index">The index</param>
        /// <returns>Element at index.</returns>
        public MethodParameterElement this[int index]
        {
            get { return (MethodParameterElement)this.Get(index); }
        }

        /// <summary>
        /// Gets the element with the given key.
        /// </summary>
        /// <param name="name">Key to look up</param>
        /// <returns>Element at that key.</returns>
        public new MethodParameterElement this[string name]
        {
            get { return (MethodParameterElement)this.Get(name); }
        }

        /// <summary>
        /// When overridden in a derived class, creates a new <see cref="T:System.Configuration.ConfigurationElement"></see>.
        /// </summary>
        /// <returns>
        /// A new <see cref="T:System.Configuration.ConfigurationElement"></see>.
        /// </returns>
        protected override ConfigurationElement CreateNewElement()
        {
            return new MethodParameterElement();
        }

        /// <summary>
        /// Gets the element key for a specified configuration element when overridden in a derived class.
        /// </summary>
        /// <param name="element">The <see cref="T:System.Configuration.ConfigurationElement"></see> to return the key for.</param>
        /// <returns>
        /// An <see cref="T:System.Object"></see> that acts as the key for the specified <see cref="T:System.Configuration.ConfigurationElement"></see>.
        /// </returns>
        protected override object GetElementKey(ConfigurationElement element)
        {
            MethodParameterElement methodParameterElement = (MethodParameterElement)element;
            return methodParameterElement.Name;
        }
    }
}